/**
 *
 */
package com.moogene.android.engine.util;

import android.graphics.Rect;

/**
 * @author 28849218
 *
 */
public class Anchor {

    public static final int LEFT_TOP = 0;

    public static final int CENTER = 1;

    public static final int RIGHT_BOTTOM = 2;

    public static final int CENTER_BOTTOM = 3;

    private int mAnchorType;

    private int mAnchorX;

    private int mAnchorY;

    private int width;

    private int height;

    private Rect dstRect;

    public Anchor(int x, int y, int width, int height){
        mAnchorX = x;
        mAnchorY = y;
        this.width = width;
        this.height = height;
        dstRect = new Rect();
    }

    public Anchor(int type, int width, int height){
        mAnchorType = type;
        this.width = width;
        this.height = height;
        switch (type) {
            case LEFT_TOP:
                mAnchorX = 0;
                mAnchorY = 0;
                break;
            case CENTER:
                mAnchorX = width >> 1;
                mAnchorY = height >> 1;
                break;
            case RIGHT_BOTTOM:
                mAnchorX = width;
                mAnchorY = height;
                break;
            case CENTER_BOTTOM:
                mAnchorX = width >> 1;
                mAnchorY = height;
                break;
        }
        dstRect = new Rect();
    }

    public int getAnchorX() {
        return mAnchorX;
    }

    public int getAnchorY() {
        return mAnchorY;
    }

    public Rect adjust(int left, int top){
        dstRect.left = left - mAnchorX;
        dstRect.right = left - mAnchorX + width;
        dstRect.top = top - mAnchorY;
        dstRect.bottom = top - mAnchorY + height;
        return dstRect;
    }

}
